Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: improve JSDoc annotations #60

Merged
merged 6 commits into from
Oct 25, 2023
Merged

chore: improve JSDoc annotations #60

merged 6 commits into from
Oct 25, 2023

Conversation

jessicamcinchak
Copy link
Member

Small tidy ups while doing presentation prep & comparing to OneApp

*/
export interface LondonProperty extends UKProperty {
region: 'London';
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this makes for a bit of a messy union type that's 'London' | string - better suggestions for handling / communicating what I'm trying to get at here?

should i just type as a proper enum with the 9 possible regions returned by https://www.planning.data.gov.uk/dataset/region? i don't think these should change often?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good question. There's basically two ways of doing this that I can think of which better describe the type we intend to be used here.

The first would be something like -

type UKRegion = string extends "London" ? never : string;

This is pretty neat as TS "trick" but basically meaningless in terms of the schema.

I think a better approach would be to define a UKRegion string union type of all 9 just as you suggest, and reference the Planning Data link as the source of these 9 strings in a comment or JSDoc.

We can then end up with Exclude<UKRegion, "London"> and Extract<UKRegion, "London"> (this second one is also the same as the string literal type "London" but is maybe more meaningful?).

Hopefully they would compile correctly into JSON schema!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing I'm super keen to discuss further with Planning Data is them being the custodian of these data dictionaries - I think this is a very meaningful and potentially quick win which may solve #51 in a satisfying way also.

Copy link
Member Author

@jessicamcinchak jessicamcinchak Oct 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Updated to type out an enum with the 9 values - only glitch to the original suggestion of Exclude... and Extract is that a LondonProperty currently extends a UKProperty which then means non-intersecting type error.

So I've gone with UKProperty having full UKRegion type as initial compromise here - still more precise than string!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok - I think to make this work then we'd need an abstract (Property?) base interface and then extend both UKProperty and LondonProperty from this probably.

What you have here though is a totally fair and sensible compromise though 👍

*/
export interface LondonProperty extends UKProperty {
region: 'London';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a good question. There's basically two ways of doing this that I can think of which better describe the type we intend to be used here.

The first would be something like -

type UKRegion = string extends "London" ? never : string;

This is pretty neat as TS "trick" but basically meaningless in terms of the schema.

I think a better approach would be to define a UKRegion string union type of all 9 just as you suggest, and reference the Planning Data link as the source of these 9 strings in a comment or JSDoc.

We can then end up with Exclude<UKRegion, "London"> and Extract<UKRegion, "London"> (this second one is also the same as the string literal type "London" but is maybe more meaningful?).

Hopefully they would compile correctly into JSON schema!

*/
export interface LondonProperty extends UKProperty {
region: 'London';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing I'm super keen to discuss further with Planning Data is them being the custodian of these data dictionaries - I think this is a very meaningful and potentially quick win which may solve #51 in a satisfying way also.

@jessicamcinchak jessicamcinchak merged commit 5aa4a1b into main Oct 25, 2023
3 checks passed
@jessicamcinchak jessicamcinchak deleted the jess/add-docs branch October 25, 2023 10:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants